package servlet;

import hbase.Book;

import hbase.HbaseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

/**
 * @author cheng
 * @date 2022-03-07 23:18
 */
@WebServlet("/bookAdd")
public class HbaseAdd extends HttpServlet {



    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String booksId = req.getParameter("booksId");
       String  name =req.getParameter("name");
        String amount = req.getParameter("amount");
        String type = req.getParameter("type");
        String bookStatus =req.getParameter("bookStatus");

//        List<String> obj_value = (new UserLogFromHBase()).getUserLogList("Student", new String[]{"StuInfo","Grades",});

        ArrayList<Book> bookArrayList = new ArrayList<>();
        Book book = new Book();
        book.setBooksId(booksId);
        book.setName(name);
        book.setAmount(amount);
        book.setBookStatus(type);
        book.setBookStatus(bookStatus);
        bookArrayList.add(book);


        HbaseUtil hbaseAddUtil = new HbaseUtil();
        String obj_value = "";
        try {

            obj_value = hbaseAddUtil.insertinfo("niit01","2181","Book",bookArrayList);
        }catch (Exception e){
            e.printStackTrace();
        }


        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw =  resp.getWriter();
        pw.write("<h1>"+  obj_value);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
